package com.situ.day3;

public class Student {
    //私有属性只能在类的内部访问
    private int id;
    private String name;
    private int age;
    private String gender;

    //无参构造方法
    //我们不写java会默认创建一个无参构造方法，只是我们看不到
    //但是如果我们自己写了任何一个构造方法，java就不再提供这个无参构造方法
    public Student() {
        System.out.println("Student.Student");
    }

    //有参构造方法
    public Student(int id, String name, int age, String gender) {
        this.id = id;
        this.name = name;
        this.age = age;
        this.gender = gender;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        if (age < 0 || age > 125) {
            //抛出异常
            return;
        }
        this.age = age;

        /*if (age >= 0 && age <= 125) {
            this.age = age;
        }*/
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        //Variable 'name' is assigned to itself
        //就近原则
        //name = name;
        //this: 代表当前类的对象
        this.name = name;
    }

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public String getGender() {
        return gender;
    }

    public void setGender(String gender) {
        this.gender = gender;
    }

    @Override
    public String toString() {
        return "Student{" +
                "id=" + id +
                ", name='" + name + '\'' +
                ", age=" + age +
                ", gender='" + gender + '\'' +
                '}';
    }
}
